﻿<%@ WebHandler Language="C#" Class="ZSContainerStepWorkReportHandler" %>

using System;
using System.Web;
using BusinessRule.DTO;
using System.Web.SessionState;
using DatabaseAccess.DBUtility;
using System.Data.OracleClient;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Web.SessionState;
using System.Configuration;
using Newtonsoft.Json;
using BusinessRule.Business;
using BusinessRule.IBusiness;
using BusinessRule.BusinessFactory;
using BusinessRule.Common;
/// <summary>
/// add by longb 2022-06-01 
/// 装试开工报工相关业务
/// </summary>

public class ZSContainerStepWorkReportHandler : IHttpHandler, IRequiresSessionState
{
    CurrentUserInfo m_UserInfo;
    uLMSCommonBusiness commonBusiness = new uLMSCommonBusiness();
    private uLMSCommonIBusiness m_CommonObj = uMESBusinessFactory.instance.GetuLMSCommonObject();
    private uLMSWorkReportIBusiness m_ReportObj = uMESBusinessFactory.instance.GetuLMSWorkReportObject();
    private uLMSQualityHistoryRecordIBusiness m_QualityHistory = uMESBusinessFactory.instance.GetQualityHistoryRecordObject();
    private uLMSStepCheckPointIBusiness m_CheckPointObj = uMESBusinessFactory.instance.GetuLMSStepCheckPointObject();
    private uLMSContainerIBusiness m_ContainerObj = uMESBusinessFactory.instance.GetuLMSContainerObject();
    private uLMSCheckIBusiness m_CheckObj = uMESBusinessFactory.instance.GetuLMSCheckObject();
    private uLMSDispatchIBusiness m_DispatchObj = uMESBusinessFactory.instance.GetuLMSDispatchObject();
    private uLMSPartPlanIBusiness m_PartPlanObj = uMESBusinessFactory.instance.GetuLMSPartPlanObject();
    private SendRequestBusiness m_sendData = new SendRequestBusiness();
    private SendRequestBusiness SendR = new SendRequestBusiness();
    private uLMSIssueERPMaterialIbusiness m_issueData = uMESBusinessFactory.instance.GetuLMSIssueERPMaterialObject();
    private uLMSEmployeeIBusiness m_EmployeeObj = uMESBusinessFactory.instance.GetuLMSEmployeeObject();
    public void ProcessRequest(HttpContext context)
    {
        try
        {
            var action = context.Request["action"].ToString();
            m_UserInfo = (CurrentUserInfo)context.Session["CurrentUserInfo"];
            switch (action)
            {
                case "getWorkTime"://获取工人-工时信息
                    getWorkTime(context);
                    break;
                case "getZSWorkReportContainerInfo": //查询工人任务单信息
                    getZSWorkReportContainerInfo(context);
                    break;
                case "addContainerStepWorkReportInfo"://工人报工操作
                    addContainerStepWorkReportInfo(context);
                    break;
                case "getWorkflowStep"://查询任务单工序工步信息
                    getWorkflowStep(context);
                    break;
                case "getStepInfo"://查询任务单工序-工步信息
                    getStepInfo(context);
                    break;
                case "lookProgress"://查看准备进度
                    lookProgress(context);
                    break;
                case "puplViewDocument"://查看工艺
                    puplViewDocument(context);
                    break;
                case "receiveDispatch"://任务接收
                    receiveDispatch(context);
                    break;
                case "reciveMaterialConfirm"://收料确认
                    reciveMaterialConfirm(context);
                    break;
                case "containerWorkflowstepOpenWork"://任务单工序开工
                    containerWorkflowstepOpenWork(context);
                    break;
                case "puplIssueOperate"://装配/分解操作
                    puplIssueOperate(context);
                    break;
                case "pupInputChechPoint"://实测值录入
                    pupInputChechPoint(context);
                    break;
                case "pupQualityCheckOrPartRecept"://质量问题查看 OR 零组件交接
                    pupQualityCheckOrPartRecept(context);
                    break;
                case "saveDailySettlementSpecProblemRecord"://保存日结工序问题记录
                    saveDailySettlementSpecProblemRecord(context);
                    break;
                case "saveBpmContainerInfo"://保存问题快反所关联批次信息
                    saveBpmContainerInfo(context);
                    break;
                case "getStepInfoList":
                    getStepInfoList(context);
                    break;
                case "getIssueConfirmData":
                    getIssueConfirmData(context);
                    break;
                case "getWorkreportmaterialrecord":
                    getWorkreportmaterialrecord(context);
                    break;
                case "insertWorkReportMaterialRecord":
                    insertWorkReportMaterialRecord(context);
                    break;
                case "deleteWorkReportMaterialRecord":
                    deleteWorkReportMaterialRecord(context);
                    break;
                case "getWRSplitmaterialrecord":
                    getWRSplitmaterialrecord(context);
                    break;
                case "insertSplitReportRecord":
                    insertSplitReportRecord(context);
                    break;
                case "getStepCheckPointList":
                    getStepCheckPointList(context);
                    break;
                case "getStepCheckPointResultList":
                    getStepCheckPointResultList(context);
                    break;
                case "saveCheckPointResult":
                    saveCheckPointResult(context);
                    break;
                case"getQualityHistoryRecord":
                    getQualityHistoryRecord(context);
                    break;
                case"getIssueMenuInfoDS":
                    getIssueMenuInfoDS(context);
                    break;
                case"partReceptSend":
                    partReceptSend(context);
                    break;    
                case"partReceptAccept":
                    partReceptAccept(context);
                    break;
                case"getEmployeeByDic":
                    getEmployeeByDic(context);
                    break;
                case"getScanContainerData":
                    getScanContainerData(context);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            var result = new uMESProcessResult();
            result.Result = false;
            result.Message = ex.Message;
            context.Response.ContentType = "text/html";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
    /// <summary>
    /// 获取工人-工时信息
    /// </summary>
    private void getWorkTime(HttpContext context)
    {
        var result = new uMESProcessResult();
        var txtTimeAttribute = string.Empty;//工时分值
        var conditionPara = new Dictionary<string, string>();
        conditionPara.Add("userattributename", "'工时分值'");
        conditionPara.Add("parentid", "'" + m_UserInfo.FactoryID + "'");
        DataTable dt = m_CommonObj.GetTableInfoByField("Userattribute", conditionPara, null);
        if (dt.Rows.Count > 0)
        {
            decimal i_dec = 0;
            if (decimal.TryParse(dt.Rows[0]["attributevalue"].ToString(), out i_dec))
            {
                txtTimeAttribute = i_dec.ToString();
            }
            else
            {
                result.Message = "工时分值:" + dt.Rows[0]["attributevalue"].ToString() + "不为数字";
            }
        }

        var para = new Dictionary<string, string>();
        var beginDate = string.Empty;
        var endDate = string.Empty;
        var strE = string.Empty;
        if (DateTime.Now.Day < 20)
        {
            strE = DateTime.Now.Year + "-" + DateTime.Now.Month.ToString().PadLeft(2, '0') + "-" + DateTime.Now.Day.ToString().PadLeft(2, '0');
            endDate = strE;
        }
        else
        {
            strE = DateTime.Now.Year + "-" + DateTime.Now.Month.ToString().PadLeft(2, '0') + "-20";
            endDate = strE;
        }
        if (DateTime.Now.Month == 1)
        {
            strE = DateTime.Now.AddYears(-1).Year + "-12-21";
        }
        else
        {
            strE = DateTime.Now.Year + "-" + DateTime.Now.AddMonths(-1).Month.ToString().PadLeft(2, '0') + "-21";
        }
        beginDate = strE;
        para.Add("EmployeeId", m_UserInfo.EmployeeID.ToString());
        para.Add("BeginDate", beginDate);
        para.Add("EndDate", endDate);
        double txtSumWorkTime = 0; //m_ReportObj.GetUserAllWorkTime(para);//总工时
        if (string.IsNullOrWhiteSpace(txtTimeAttribute)) { txtTimeAttribute = "1"; }
        var txtSumJX = (Convert.ToDecimal(txtSumWorkTime) * Convert.ToDecimal(txtTimeAttribute)).ToString("N3");//总绩效
        var Work = new Dictionary<string, string>();
        Work.Add("txtTimeAttribute", txtTimeAttribute);
        Work.Add("txtSumWorkTime", txtSumWorkTime.ToString());
        Work.Add("txtSumJX", txtSumJX);
        result.ReturnData = Work;
        var LossReason = m_CommonObj.GetLossReasonByGroupName("超期报工原因组");
        result.DBTable = LossReason;
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查询工人任务单信息
    /// </summary>
    /// <param name="context"></param>
    private void getZSWorkReportContainerInfo(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var para = new Dictionary<string, string>();
        para.Add("FactoryID", m_UserInfo.FactoryID);//分厂
        para.Add("TeamID", m_UserInfo.TeamID);//班组
        para.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        if (!string.IsNullOrEmpty(dic["ContainerNo"]))
        {
            para.Add("ContainerNo", dic["ContainerNo"]);
        }
        if (!string.IsNullOrEmpty(dic["MachineStart"]))
        {
            para.Add("MachineStart", dic["MachineStart"]);
        }
        if (!string.IsNullOrEmpty(dic["MachineEnd"]))
        {
            para.Add("MachineEnd", dic["MachineEnd"]);
        }
        if (!string.IsNullOrEmpty(dic["BeginDate"]))
        {
            para.Add("BeginDate", dic["BeginDate"]);
        }
        if (!string.IsNullOrEmpty(dic["EndDate"]))
        {
            para.Add("EndDate", dic["EndDate"]);
        }
        var result = new uMESProcessResult();
        DataTable dtResult = m_ReportObj.GetZSWorkReportContainerInfo(para, true);
        result.Result = dtResult.Rows.Count > 0;
        result.DBTable = dtResult;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查询任务单工序工步信息
    /// </summary>
    /// <param name="context"></param>
    private void getWorkflowStep(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var para = new Dictionary<string, string>();
        para.Add("WorkflowID", dic["WORKFLOWID"]);
        para.Add("ContainerID", dic["CONTAINERID"]);
        para.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        var result = new uMESProcessResult();
        var dtResult = m_ReportObj.GetWorkerNotReportWorkflowstepInfo(para, true);
        result.Result = dtResult.Rows.Count > 0;
        result.DBTable = dtResult;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查询任务单工序-工步信息
    /// </summary>
    /// <param name="context"></param>
    private void getStepInfo(HttpContext context)
    {
        var dt = JsonConvert.DeserializeObject<DataTable>(context.Request["data"].ToString());
        var workflowStepIDs = string.Empty;
        foreach (DataRow row in dt.Rows)
        {
            if (string.IsNullOrWhiteSpace(workflowStepIDs))
            {
                workflowStepIDs += " WS.WORKFLOWSTEPID='" + row["workflowStepID"] + "'";
            }
            else
            {
                workflowStepIDs += " OR WS.WORKFLOWSTEPID='" + row["workflowStepID"] + "'";
            }
        }
        var ContainerID = context.Request["ContainerID"].ToString();
        var dtResult = m_CommonObj.GetStepInfo_InfoByWorkflowStepIDs(workflowStepIDs, ContainerID, m_UserInfo.EmployeeID.ToString(), "2", true);
        var result = new uMESProcessResult();
        result.Result = dtResult.Rows.Count > 0;
        result.DBTable = dtResult;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查看准备进度
    /// </summary>
    private void lookProgress(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var data = new Dictionary<string, string>();
        data.Add("ContainerNo", dic["CONTAINERNO"]);
        data.Add("machinepname", dic["MACHINENAME"]);
        data.Add("ProductName", dic["PRODUCTDESC"]);
        data.Add("ProductDesc", dic["PRODUCTDESC"]);
        data.Add("machineStepName", dic["MACHINESTEPNAME"]);
        data.Add("plannedstartdate", dic["PLANNEDSTARTDATE"]);
        data.Add("plannedcompletiondate", dic["PLANNEDCOMPLETIONDATE"]);
        data.Add("mfgOrdernName", dic["MFGORDERNAME"]);
        data.Add("WorkflowStepName", dic["WORKFLOWSTEPNAME"]);
        data.Add("mfgorderid", dic["MFGORDERID"]);
        context.Session["wgResult"] = data;
        var result = new uMESProcessResult();
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 查看工艺
    /// </summary>
    /// <param name="context"></param>
    private void puplViewDocument(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var poupDt = new DataTable();
        poupDt.Columns.Add("ProductID");
        poupDt.Columns.Add("WorkflowID");
        DataRow row = poupDt.NewRow();
        row["ProductID"] = dic["PRODUCTID"];
        row["WorkflowID"] = dic["WORKFLOWID"];
        poupDt.Rows.Add(row);
        context.Session["ProcessDocument"] = poupDt;
        var result = new uMESProcessResult();
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 任务接收
    /// </summary>
    private void receiveDispatch(HttpContext context)
    {
        var strContainerStepDispatchIDs = context.Request["DispatchIDs"].ToString();
        var para = new Dictionary<string, string>();
        para.Add("type", "1");
        para.Add("ContainerStepDispatchIDs", strContainerStepDispatchIDs);
        para.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        var rows = m_ReportObj.ReceviceDispatch(para);
        var result = new uMESProcessResult();
        result.Result = rows > 0;
        result.Message = result.Result ? "任务接收成功" : "任务已接收";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 收料确认
    /// </summary>
    /// <param name="context"></param>
    private void reciveMaterialConfirm(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var data = new Dictionary<string, string>();
        data.Add("ContainerNo", dic["CONTAINERNO"]);
        data.Add("machinepname", dic["MACHINENAME"]);
        data.Add("ProductName", dic["PRODUCTDESC"]);
        data.Add("ProductDesc", dic["PRODUCTDESC"]);
        data.Add("machineStepName", dic["MACHINESTEPNAME"]);
        data.Add("plannedstartdate", dic["PLANNEDSTARTDATE"]);
        data.Add("plannedcompletiondate", dic["PLANNEDCOMPLETIONDATE"]);
        data.Add("mfgOrdernName", dic["MFGORDERNAME"]);
        data.Add("WorkflowStepName", dic["WORKFLOWSTEPNAME"]);
        context.Session["OPwgResult"] = data;
        var result = new uMESProcessResult();
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    //任务单 -工序开工
    private void containerWorkflowstepOpenWork(HttpContext context)
    {
        var result = new uMESProcessResult();
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var paradt = JsonConvert.DeserializeObject<DataTable>(context.Request["dt"].ToString());
        dic.Add("eplID", m_UserInfo.EmployeeID.ToString());
        dic.Add("TransportType", "1");
        dic.Add("workflowstepid", string.Empty);
        var msg = string.Empty;
        var workflowstepIDS = string.Empty;
        var IsOpen = m_CommonObj.GetFatoryAttributes(m_UserInfo.FactoryID, "开工检查限制");
        foreach (DataRow row in paradt.Rows)
        {
            if (row["STATUS"].ToString().Equals("已接收"))
            {
                workflowstepIDS += row["WORKFLOWSTEPID"].ToString() + ",";
                dic["workflowstepid"] = row["WORKFLOWSTEPID"].ToString();
                var dt = m_sendData.GetBigSmallConfirmData(dic); //'配送进度
                var tools = m_sendData.GetZsRequiredToolsTransport(dic);
                var auxMaterial = m_sendData.GetWorkFlowStepAuxMaterialData(dic);
                var Str = String.Empty;
                if (dt.Rows.Count > 0)
                {
                    var dv = dt.DefaultView;
                    dv.RowFilter = "SENDQTY>=FIRSTASSEMBLEQTY";
                    var dtt = dv.ToTable();
                    if (dt.Rows.Count != dtt.Rows.Count) { Str += "大小件"; }
                }
                if (tools.Rows.Count > 0)
                {
                    var dvv = tools.DefaultView;
                    //dvv.RowFilter = "QTY<=PREPAREQTY";
                    var dttt = dvv.ToTable();
                    if (tools.Rows.Count != dttt.Rows.Count) { Str += "工装工具"; }
                }
                if (auxMaterial.Rows.Count > 0)
                {
                    var dvvv = auxMaterial.DefaultView;
                    //dvvv.RowFilter = "QTY<=PREPAREQTY";
                    var dtttt = dvvv.ToTable();
                    if (auxMaterial.Rows.Count != dtttt.Rows.Count) { Str += "辅材"; }
                }
                if (!String.IsNullOrWhiteSpace(Str))
                {
                    msg += "【" + row["WORKFLOWSTEPID"].ToString() + "】所需" + Str + "/";
                }
            }
        }
        if (!string.IsNullOrWhiteSpace(msg) && IsOpen.Equals("是"))
        {
            result.Message = msg + "未准备完成，不能开工";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (string.IsNullOrWhiteSpace(workflowstepIDS))
        {
            result.Message = "请勾择至少一条【已接收】工序再进行操作";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        dic.Add("workflowstepID", workflowstepIDS.TrimEnd(','));
        result.Result = SendR.UpdateOpenWork(dic) > 0;
        result.Message = result.Result ? "开工成功" : "开工失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 装配/分解操作
    /// </summary>
    /// <param name="context"></param>
    private void puplIssueOperate(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        dic.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        context.Session["PopupData"] = dic;
        var result = new uMESProcessResult();
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    //实测值录入
    private void pupInputChechPoint(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["mdata"].ToString());
        var stepinfoDT = JsonConvert.DeserializeObject<DataTable>(context.Request["data"].ToString());
        var checkData = new DataTable();
        checkData.Columns.Add("ProductId");
        checkData.Columns.Add("ProductName");
        checkData.Columns.Add("ProductRev");
        checkData.Columns.Add("ProductDescription");
        checkData.Columns.Add("WorkFlowStepId");
        checkData.Columns.Add("StepinfoId");
        checkData.Columns.Add("WorkFlowStepName");
        checkData.Columns.Add("StepinfoName");
        checkData.Columns.Add("ContainerId");
        checkData.Columns.Add("ContainerName");
        checkData.Columns.Add("ContainerType");
        checkData.Columns.Add("ContainerTypeName");
        checkData.Columns.Add("MfgorderName");
        checkData.Columns.Add("Machine");
        checkData.Columns.Add("TogetherFlag");

        DataTable dt = m_ReportObj.GetProductInfobyCid(dic["ContainerID"]);
        if (dt.Rows.Count > 0)
        {
            for (var i = 0; i < stepinfoDT.Rows.Count; i++)
            {
                var para = new Dictionary<string, string>();
                para.Add("ContainerID", dic["ContainerID"]);
                para.Add("ProductID", dt.Rows[0]["ProductId"].ToString());
                para.Add("StepID", stepinfoDT.Rows[i]["WORKFLOWSTEPID"].ToString());
                var StepinfoID=string.IsNullOrWhiteSpace(stepinfoDT.Rows[i]["STEPINFOID"].ToString()) ? string.Empty : stepinfoDT.Rows[i]["STEPINFOID"].ToString();
                para.Add("StepinfoID", StepinfoID);
                //if (!string.IsNullOrWhiteSpace(StepinfoID))
                //{
                //    para.Add("StepinfoID", StepinfoID);
                //}
                DataTable dtt = m_CheckPointObj.GetStepCheckPointList(para).DBTable;
                if (dtt.Rows.Count == 0) { continue; }

                DataRow Item = checkData.NewRow();
                Item["ProductName"] = dt.Rows[0]["ProductName"].ToString();
                Item["ProductId"] = dt.Rows[0]["ProductId"].ToString();
                Item["ProductDescription"] = dt.Rows[0]["description"].ToString();
                Item["ProductRev"] = dt.Rows[0]["productrevision"].ToString();
                Item["MfgorderName"] = dt.Rows[0]["MfgorderName"].ToString();
                Item["TogetherFlag"] = dt.Rows[0]["TogetherFlag"].ToString();
                Item["ContainerType"] = dt.Rows[0]["ContainerType"].ToString().Equals("7") ? "单件加工" : "";
                Item["ContainerTypeName"] = dt.Rows[0]["ContainerTypeName"].ToString();

                Item["StepinfoId"] = stepinfoDT.Rows[i]["STEPINFOID"].ToString();
                Item["WorkFlowStepId"] = stepinfoDT.Rows[i]["WORKFLOWSTEPID"].ToString();
                Item["StepinfoName"] = stepinfoDT.Rows[i]["STEPINFONAME"].ToString();
                Item["WorkFlowStepName"] = stepinfoDT.Rows[i]["WORKFLOWSTEPNAME"].ToString();
                Item["ContainerId"] = dic["ContainerID"];
                Item["ContainerName"] = dic["ContainerName"];
                Item["Machine"] = dic["Machine"];
                checkData.Rows.Add(Item);
            }
        }
        var result = new uMESProcessResult();
        result.DBTable = checkData;
        result.Result = true;
        context.Session["PopupData"] = checkData;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    //质量问题查看 OR 零组件交接
    private void pupQualityCheckOrPartRecept(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        context.Session["PopupData"] = dic;
        var result = new uMESProcessResult();
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 保存日结工序问题记录
    /// </summary>
    /// <param name="context"></param>
    private void saveDailySettlementSpecProblemRecord(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var insertSQL = @"insert into ZSDaySpecProblemRecord(ZSDaySpecProblemRecordID,ProblemRecord,ContainerID,WorkFlowStepIDS,StepInfoIDS,CreateDate,CreateEmployeeID)
                           values(sys_guid(),'{0}','{1}','{2}','{3}',sysdate,'{4}') ";
        var result = new uMESProcessResult();
        result.Result = DatabaseHelper.ExecuteSql(string.Format(insertSQL, dic["Record"], dic["ContainerID"], dic["WorkFlowStepID"], dic["StepInfoID"], m_UserInfo.EmployeeID.ToString())) > 0;
        result.Message = result.Result ? "保存成功" : "保存失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 工人报工操作
    /// </summary>
    /// <param name="context"></param>
    private void addContainerStepWorkReportInfo(HttpContext context)
    {
        var result = new uMESProcessResult();
        //1.历史质量问题--验证
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        DataTable dt = m_QualityHistory.GetQualityHistoryRecord(para);
        //if (dt.Select("isAdd='是'").Length > 0)
        //{
        //    result.Message = "请确认历史质量问题";
        //    context.Response.Write(JsonConvert.SerializeObject(result));
        //    return;
        //}
        //2.装配完、实测值录入完--判断
        var ZPStr = String.Empty;
        var SCZStr = String.Empty;
        DataTable wgStepInfo = JsonConvert.DeserializeObject<DataTable>(context.Request["wgStepInfo"].ToString());
        foreach (DataRow row in wgStepInfo.Rows)
        {
            var oQuery = new Dictionary<string, string>();
            oQuery.Add("ContainerID", para["CONTAINERID"]);
            oQuery.Add("StepID", row["WorkflowStepID"].ToString());
            oQuery.Add("StepinfoID", row["StepinfoID"].ToString());
            uMESProcessResult Result = m_CheckPointObj.GetStepCheckPointList(oQuery); //工序检验项--实测值录入记录
            DataTable dtt = Result.DBTable;
            DataView dv = dtt.DefaultView;
            dv.RowFilter = "status='未录'";
            if (dv.ToTable().Rows.Count > 0)
            {
                if (!SCZStr.Contains(row["WorkflowStepName"].ToString()))
                {
                    SCZStr += row["WorkflowStepName"] + ",";
                }
            }
            DataTable Dt = m_ReportObj.GetWorkreportmaterialrecordStatus(oQuery); //工序大小零件装配记录
            DataView dv1 = Dt.DefaultView;
            dv1.RowFilter = "ISFINISH='1'";
            DataTable table = dv1.ToTable();
            if (Dt.Rows.Count != table.Rows.Count)
            {
                if (ZPStr.Contains(row["WorkflowStepName"].ToString()))
                {
                    ZPStr += row["WorkflowStepName"] + ",";
                }
            }
            SealAndIssueBusiness m_issueData = new SealAndIssueBusiness();
            oQuery.Add("ContainerNo", para["CONTAINERNO"]);
            oQuery.Add("workflowstepid", row["WorkflowStepID"].ToString());
            oQuery.Add("TransportType", "1");
            oQuery.Add("mfgorderid", para["MFGORDERID"]);
            DataTable pdt = m_issueData.GetProgressData(oQuery); //工序所需大小零件清单
            if (pdt.Rows.Count > 0 && Dt.Rows.Count == 0)
            {
                if (ZPStr.Contains(row["WorkflowStepName"].ToString()))
                {
                    ZPStr += row["WorkflowStepName"] + ",";
                }
            }
        }
        if (!string.IsNullOrWhiteSpace(ZPStr))
        {
            result.Message = "工序[" + ZPStr.Substring(0, ZPStr.LastIndexOf(",")) + "]未装配完，不能进行报工";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        if (!string.IsNullOrWhiteSpace(SCZStr))
        {
            result.Message = "工序[" + SCZStr.Substring(0, SCZStr.LastIndexOf(",")) + "]实测值未录入完，不能进行报工";
            context.Response.Write(JsonConvert.SerializeObject(result));
            return;
        }
        //3.报工超期判断
        if (string.IsNullOrWhiteSpace(para["ddlReasonType"]))
        {
            DateTime DateTimeFinish;
            if (DateTime.TryParse(para["PLANNEDCOMPLETIONDATE"].ToString(), out DateTimeFinish))
            {
                if (DateTime.Now.Date > DateTimeFinish.Date)
                {
                    result.Message = "报工超期，请输入超期原因类型";
                    context.Response.Write(JsonConvert.SerializeObject(result));
                    return;
                }
            }
        }
        //4.报工卡关 
        if (!string.IsNullOrWhiteSpace(para["MACHINESTEPID"]))
        {
            //4.1发动机大阶段卡关判断
            DataTable dtM = m_CommonObj.GetWorkFlowSetpsByWorkflowStepID(para["MACHINESTEPID"]);
            if (dtM.Rows.Count > 0)
            {
                var i_sequence = Convert.ToInt32(dtM.Rows[0]["SEQUENCE"].ToString());
                var str_sequence = string.Empty;
                //4.2依照逻辑判断当前大阶段之前的阶段是否已经完工
                if (i_sequence > 3)
                {
                    if (i_sequence == 4) { str_sequence = "1,2,3"; }
                    else if (i_sequence == 8) { str_sequence = "6"; }
                    else if (i_sequence == 11) { str_sequence = "10,9,8"; }
                    else if (i_sequence == 10 || i_sequence == 9) { str_sequence = "7"; }
                    else { str_sequence = (i_sequence - 1).ToString(); }
                    DataTable dtPre = m_ReportObj.CheckPreStepComplete(para["MFGORDERID"], str_sequence);
                    if (dtPre.Rows.Count > 0)
                    {
                        //result.Message = "本阶段之前有任务单" + dtPre.Rows[0]["containerno"].ToString() + "在大阶段" + dtPre.Rows[0]["workflowstepname"].ToString() + "没有完工";
                        //context.Response.Write(JsonConvert.SerializeObject(result));
                        //return;
                    }
                }
            }
        }
        //5.获取批次是初装还是检装
        String typeStr = m_ContainerObj.CheckFirstSecondIssueNew(para["CONTAINERID"]);
        foreach (DataRow row in wgStepInfo.Rows)
        {
            var DTO = new ContainerStepWorkReportDTO();
            DTO.ContainerID = para["CONTAINERID"];
            DTO.FactoryID = m_UserInfo.FactoryID;
            DTO.WorkCenterID = m_UserInfo.WorkCenterID;
            DTO.TeamID = m_UserInfo.TeamID;
            DTO.WorkflowstepID = row["WorkflowStepID"].ToString();
            DTO.StepInfoID = "";
            if (!string.IsNullOrWhiteSpace(row["StepInfoID"].ToString()))
            {
                DTO.StepInfoID = row["StepInfoID"].ToString();
            }
            DTO.ResourceID = "";
            DTO.WorkerID = m_UserInfo.EmployeeID.ToString();
            DTO.CheckerID = "";
            DTO.SelfCheckOutofToleranceQty = 0;
            DTO.SelfCheckLossQty = 0;
            DTO.SeleCheckQualifiedQty = 0;
            DTO.Qty = 1;
            DTO.CheckType = string.IsNullOrWhiteSpace(typeStr) ? 1 : int.Parse(typeStr);//返回为空则类型是初装
            DTO.ReasonType = para["ddlReasonType"];
            DTO.ReasonDesc = para["txtReason"];
            DTO.ContainerStepDispatchID = row["ContainerStepDispatchID"].ToString();
            DTO.ContainerStepWorkReportID = System.Guid.NewGuid().ToString();
            if (m_ReportObj.AddContainerStepWorkReportInfo(DTO, "split"))//此处使用以前分批创建报工使用的结转标识（服务不处理）
            {
                if (m_UserInfo.WorkCenter.IndexOf("生产保障") >= 0)//生产保障---装试装配中心
                {
                    string message = "自动检验失败";
                    if (!ZSAutoCheck(DTO, para["WORKFLOWID"].ToString(), out message))
                    {
                        result.Message = message;
                        break;
                    }
                }
                var para1 = new Dictionary<string, string>();
                para1.Add("type", "2");
                para1.Add("WorkerID", DTO.WorkerID);
                para1.Add("ContainerStepDispatchID", DTO.ContainerStepDispatchID);
                if (!(m_ReportObj.ReceviceDispatch(para1) > 0))
                {
                    result.Message = "单独写入或更新任务接收人员ID失败";
                    break;
                }
            }
            else
            {
                result.Message = "添加报工记录失败";
                break;
            }
        }
        result.Result = true;
        result.Message = "报工成功";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    /// <summary>
    /// 生产保障处在此自动检验并判断是否执行大阶段完成
    /// </summary>
    /// <param name="ReportDto"></param>
    /// <returns></returns>
    public bool ZSAutoCheck(ContainerStepWorkReportDTO ReportDto, string workflowid, out string Message)
    {
        var chkDTO = new ContainerCheckInfoDTO();
        chkDTO.ContainerID = ReportDto.ContainerID;
        chkDTO.FactoryID = ReportDto.FactoryID;
        chkDTO.WorkflowstepID = ReportDto.WorkflowstepID;
        chkDTO.StepInfoID = ReportDto.StepInfoID;
        chkDTO.CheckerID = ReportDto.WorkerID;
        chkDTO.CheckQty = 1;
        chkDTO.AcceptanceQty = 1;
        chkDTO.LossQty = 0;
        chkDTO.ReworkQty = 0;
        chkDTO.DefectQty = 0;
        chkDTO.ContainerCheckInfoID = ReportDto.ContainerStepWorkReportID;
        chkDTO.CheckNote = String.Empty;
        chkDTO.CheckTypeNote = 2;
        chkDTO.FirstCheckBillNo = String.Empty;
        chkDTO.ContainerStepWorkReportID = ReportDto.ContainerStepWorkReportID;
        chkDTO.IsUse = 0;
        try
        {
            var res = m_CheckObj.AddZSContainerCheckInfo(chkDTO);
            if (!res)
            {
                Message = "检验异常";
                return false;
            }
            else
            {
                //1.判断是否完工（所有工序工步完成）
                var i_Stepinfo = m_DispatchObj.GetStepInfobyWorkflowId(workflowid).Rows.Count;
                var i_CheckInfo = m_DispatchObj.GetCheckInfoDataByCid(chkDTO.ContainerID).Rows.Count;
                //2.如果已经检验合格的记录=工序工步的记录,最后一道工序工步
                if (i_Stepinfo == i_CheckInfo)
                {
                    var para = new Dictionary<string, string>();
                    para.Add("ContainerId", chkDTO.ContainerID);
                    para.Add("StepId", chkDTO.WorkflowstepID);
                    para.Add("StepInfoId", chkDTO.StepInfoID);
                    if (!m_PartPlanObj.UpdateUseComplete(para))
                    {
                        Message = "完工标记更新异常";
                        return false;
                    }
                }
                Message = "";
                return true;
            }
        }
        catch (Exception ex)
        {
            Message = ex.Message;
            return false;
        }
    }

    /// <summary>
    /// 保存问题快反所关联批次信息 add zhunan 2023.5.11
    /// </summary>
    /// <param name="context"></param>
    private void saveBpmContainerInfo(HttpContext context)
    {
        var dic = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        string sql = @"
SELECT cci.productname,cci.togetherflag,cci.familylistnames,cci.workflowstepname,cci.specno,cci.specname,cci.workflowname,cci.workflowrevision,NULL resourcename
FROM containercurrentinfo cci WHERE cci.containerid = '{0}'
";
        DataTable dt = DatabaseHelper.Query_ReturnDatTable(string.Format(sql, dic["containerid"].ToString()));
        string productname = "", togetherflag = "", workflowstepname = "", specname = "", specno = "", familylistnames = "", workflowname = "", workflowrevision = "", resourcename = "";
        if (dt.Rows.Count > 0)
        {
            productname = dt.Rows[0]["productname"].ToString();
            togetherflag = dt.Rows[0]["togetherflag"].ToString();
            workflowstepname = dt.Rows[0]["workflowstepname"].ToString();
            specname = dt.Rows[0]["specname"].ToString();
            specno = dt.Rows[0]["specno"].ToString();
            familylistnames = dt.Rows[0]["familylistnames"].ToString();
            workflowname = dt.Rows[0]["workflowname"].ToString();
            workflowrevision = dt.Rows[0]["workflowrevision"].ToString();
            resourcename = dt.Rows[0]["resourcename"].ToString();
        }
        //插入前先删除当前用户的历史数据
        var delSql = string.Format("DELETE bpm_containerinfo t WHERE t.createuser = '{0}'", dic["createuser"].ToString());
        DatabaseHelper.ExecuteSql(delSql);
        //插入数据
        var insertSQL = @"
INSERT INTO bpm_containerinfo(createuser,createdate,productname,togetherflag,workflowstepname,specname,specno,familylistnames,workflowname,workflowrevision,resourcename)
VALUES('{0}',SYSDATE,'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')
";
        insertSQL = string.Format(insertSQL, dic["createuser"].ToString(), productname, togetherflag, workflowstepname, specname, specno, familylistnames, workflowname, workflowrevision, resourcename);
        var result = new uMESProcessResult();
        result.Result = DatabaseHelper.ExecuteSql(string.Format(insertSQL, dic["containerid"])) > 0;
        result.Message = result.Result ? "保存成功" : "保存失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    /// <summary>
    /// 装配操作页面使用
    /// </summary>
    /// <param name="context"></param>
    private void getStepInfoList(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        para.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        DataTable dt = m_ReportObj.GetStepInfoList(para, true);
        //DataView dv = dt.DefaultView;
        //dt = dv.ToTable(true, ["WorkflowStepID", "WORKFLOWSTEPNAME", "STEPINFOID", "STEPINFODES"]);
        var result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = dt;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getIssueConfirmData(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        DataTable dt = m_ReportObj.GetIssueConfirmData(para);
        if (dt.Rows.Count == 0)
        {
            para.Remove("StepInfoId");
            dt = m_ReportObj.GetIssueConfirmData(para);
        }
        var result = new uMESProcessResult();
        result.Result = dt.Rows.Count > 0;
        result.Message = result.Result ? "" : "工序没有大小件信息";
        result.DBTable = dt;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getWorkreportmaterialrecord(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        DataSet ds = m_ReportObj.GetWorkreportmaterialrecord(para);
        var result = new uMESProcessResult();
        result.Result = true;
        result.DBDataSet = ds;
        result.ReturnData = m_ReportObj.GetHasIssueQty(para);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void insertWorkReportMaterialRecord(HttpContext context)
    {
        var result = new uMESProcessResult();
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var workreportmaterialrecordid = para["workreportmaterialrecordid"];
        var typeStr = m_ContainerObj.CheckFirstSecondIssueNew(para["ContainerId"]);
        var DTO = new ContainerStepWorkReportDTO();
        DTO.IsFinish = para["IsFinish"];
        DTO.CheckType = Convert.ToInt32(typeStr);
        DTO.ContainerID = para["ContainerId"];
        DTO.WorkflowstepID = para["WorkflowStepID"];
        DTO.StepInfoID = para["StepInfoID"];
        DTO.WorkerID = m_UserInfo.EmployeeID;
        DTO.Qty = Convert.ToInt32(Convert.ToInt32(para["NOWQTY"]));
        DTO.Note = "";
        DTO.IsUse = 0;
        DTO.IssueType = Convert.ToInt32(para["Type"]);
        DTO.IssueReason = Convert.ToInt32(para["Reason"]);
        DTO.GuideDoc = para["Doc"];
        DTO.IssueERPMaterialID = para["ISSUEERPMATERIALID"];
        if (!string.IsNullOrWhiteSpace(workreportmaterialrecordid))
        {
            DTO.WorkReportMaterialRecordID = para["workreportmaterialrecordid"];
            result.Result = m_ReportObj.DelWorkreportmaterialrecord(DTO.WorkReportMaterialRecordID);
        }
        DTO.WorkReportMaterialRecordID = System.Guid.NewGuid().ToString();
        result.Result = m_ReportObj.AddWorkReportMaterialRecord(DTO);
        if (para["IsFinish"].Equals("1") && result.Result)
        {
            m_ReportObj.UpdateWorkreportmaterialrecord(DTO);
        }
        result.Message = result.Result ? "装配成功" : "装配失败";
        //if(result.Result){
        //    var paraa=new Dictionary<string,string>();
        //    paraa.Add("stepinfoid", para["StepInfoID"]);
        //    paraa.Add("workflowstepid", para["WorkflowStepID"]);
        //    paraa.Add("issueerpmaterialid", para["ISSUEERPMATERIALID"]);
        //    result.ReturnData = m_ReportObj.GetHasIssueQty(paraa);
        //}
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void deleteWorkReportMaterialRecord(HttpContext context)
    {
        var result = new uMESProcessResult();
        var workreportmaterialrecordid = context.Request["workreportmaterialrecordid"].ToString();
        result.Result = m_ReportObj.DelWorkreportmaterialrecord(workreportmaterialrecordid);
        result.Message = result.Result ? "删除成功" : "删除失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getWRSplitmaterialrecord(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        uMESProcessResult result = m_ReportObj.GetWRSplitmaterialrecord(para);
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void insertSplitReportRecord(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        var DTO = new ContainerStepWorkReportDTO();
        DTO.ContainerID = para["ContainerID"];
        DTO.WorkflowstepID = para["WORKFLOWSTEPID"];
        DTO.StepInfoID = "";
        DTO.WorkerID = m_UserInfo.EmployeeID;
        DTO.Qty = Convert.ToInt32(para["NOWQTY"]);
        DTO.Note = "";
        DTO.IsUse = 0;
        DTO.IssueType = 0;
        DTO.IssueReason = Convert.ToInt32(para["Reason"]);
        DTO.GuideDoc = para["Doc"];
        DTO.IssueERPMaterialID = para["ISSUEERPMATERIALID"];
        DTO.WorkReportMaterialRecordID = para["WORKREPORTMATERIALRECORDID"];
        DTO.SplitReportMaterialRecordID = System.Guid.NewGuid().ToString();
        uMESProcessResult result = new uMESProcessResult();
        result.Result = m_ReportObj.AddSplitReportMaterialRecord(DTO);
        result.Message = result.Result ? "分解成功" : "分解失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }



    private void getStepCheckPointList(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        //if (string.IsNullOrWhiteSpace(para["StepinfoID"])) { para.Remove("StepinfoID"); }
        DataTable dt = m_CheckPointObj.GetStepCheckPointList(para).DBTable;
        var strFirstSecondIssueFlag = m_ContainerObj.CheckFirstSecondIssueNew(para["ContainerID"]);
        DataView dv = dt.DefaultView;
        if( strFirstSecondIssueFlag.Equals("1")) {
           dv.RowFilter = "bubblenumber='初装' or bubblenumber='通用'";
        }
        else if(strFirstSecondIssueFlag.Equals("2")) {
          dv.RowFilter = "bubblenumber='检装' or bubblenumber='通用'";
         }
         dt = dv.ToTable();
        uMESProcessResult result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = dt;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    private void getStepCheckPointResultList(HttpContext context)
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        DataTable crDT = m_CheckPointObj.GetStepCheckPointResultData(para);
        foreach (DataRow dr in crDT.Rows)
        {
            if (!string.IsNullOrWhiteSpace(dr["WORKCHECKPOINTRESULTNOTE"].ToString()))
            {
                dr["WORKCHECKPOINTRESULTNOTE"] = ConverCode(dr["WORKCHECKPOINTRESULTNOTE"].ToString(), context);
            }
            if (!string.IsNullOrWhiteSpace(dr["CHECKPOINTRESULTNOTE"].ToString()))
            {
                dr["CHECKPOINTRESULTNOTE"] = ConverCode(dr["CHECKPOINTRESULTNOTE"].ToString(), context);
            }
        }
        uMESProcessResult result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = crDT;
        result.ReturnData = crDT;

        context.Response.Write(JsonConvert.SerializeObject(result));
    }



    private string ConverCode(string code, HttpContext context)
    {
        var strPagePath = context.Request.Path;
        var dt = new DataTable();
        dt = null;
        try
        {
            return DataAdjust.ParseCode(code, "/InSiteWebApplication/ImageTemp/");
        }
        catch (Exception ex)
        {
            return code;
        }
    }

    private void saveCheckPointResult(HttpContext context)
    {
        var checkPointResultDT = JsonConvert.DeserializeObject<DataTable>(context.Request["data"].ToString());//检测项结果
        uMESProcessResult result = new uMESProcessResult();
        var isWorker = string.Empty;
        var strRole = m_CommonObj.GetEnterpriseAttributes("检验员角色");
        if(m_UserInfo.Roles.Contains(strRole)){isWorker = "0";}
        if (!m_UserInfo.Roles.Contains(strRole))
        {
            strRole = m_CommonObj.GetEnterpriseAttributes("工人角色");
            isWorker = m_UserInfo.Roles.Contains(strRole) ? "1" : "0";
        }
        if (string.IsNullOrWhiteSpace(isWorker))
        {
            result.Message = "需要工人或检验员角色进行实测值信息录入";
            context.Response.Write(JsonConvert.SerializeObject(result));
        }
        var usingImg = ConfigurationManager.AppSettings["UsingCheckImageSavePath"];
        Boolean isUseIP = ConfigurationManager.AppSettings["IsUseIP"].Equals("1") ? true : false;
        foreach (DataRow dr in checkPointResultDT.Rows)
        {
            var oQuery = new Dictionary<string, string>();
            oQuery.Add("CheckerID", m_UserInfo.EmployeeID);
            oQuery.Add("FactoryID", m_UserInfo.FactoryID);
            oQuery.Add("isWorker", isWorker);

            oQuery.Add("ContainerID", context.Request["ContainerID"].ToString());
            oQuery.Add("StepCheckPointID", dr["StepCheckPointID"].ToString());
            oQuery.Add("Notes", dr["NOTES"].ToString());
            oQuery.Add("CheckPointResultNote", isWorker.Equals("1") ? dr["WORKCHECKPOINTRESULTNOTE"].ToString() : dr["CHECKPOINTRESULTNOTE"].ToString());
            oQuery.Add("WORKCHECKPOINTRESULTNOTEDIS", m_CheckPointObj.ConvertTohtml(isWorker.Equals("1") ? dr["WORKCHECKPOINTRESULTNOTE"].ToString() : dr["CHECKPOINTRESULTNOTE"].ToString(), usingImg, isUseIP));
            //判断当前录入次数是否大于最大录入次数
            var inputSeq = m_CheckPointObj.GetMaxSequenceById(oQuery["StepCheckPointID"].ToString(), oQuery["ContainerID"].ToString(), oQuery["FactoryID"].ToString());
            var r = 0;
            if (string.IsNullOrWhiteSpace(dr["StepCheckPointResultID"].ToString()) || int.TryParse(dr["StepCheckPointResultID"].ToString(), out r))
            {
                if (Convert.ToInt32(dr["INPUTNUM"].ToString()) > inputSeq)
                {
                    oQuery.Add("StepCheckPointResultID", Guid.NewGuid().ToString());
                    result.Result = m_CheckPointObj.AddStepCheckResultInfo(oQuery);
                }
            }
            else
            {
                oQuery.Add("StepCheckPointResultID", dr["StepCheckPointResultID"].ToString());
                result.Result = m_CheckPointObj.UpdateStepCheckResultInfo(oQuery);
            }
        }
        result.Message = result.Result ? "实测值录入成功" : "实测值录入失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getQualityHistoryRecord(HttpContext context) 
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        DataTable dt = m_QualityHistory.GetQualityHistoryRecord(para);
        uMESProcessResult result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = dt;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getIssueMenuInfoDS(HttpContext context) 
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string, string>>(context.Request["data"].ToString());
        para.Add("PartType", "0");
        DataTable dt = m_issueData.GetIssueMenuInfoDS(para).Tables["dtIssueSum"];
        para["PartType"]="1";
        DataTable dt1 = m_issueData.GetIssueMenuInfoDS(para).Tables["dtIssueSum"];
        uMESProcessResult result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = dt;
        result.ReturnData = dt1;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }
    private void partReceptSend(HttpContext context)
    {
        var bigsmall = JsonConvert.DeserializeObject<DataTable>(context.Request["bigsmall"].ToString());
        var sqlTran = new ArrayList();
        uMESProcessResult result = new uMESProcessResult();
        foreach (DataRow dr in bigsmall.Rows)
        {
            var Status = m_issueData.GetPartsStatus(dr["ISSUEERPMATERIALID"].ToString());
            if (string.IsNullOrWhiteSpace(Status)) 
            {
                var para = new Dictionary<string, string>();
                para.Add("ISSUEERPMATERIALID", dr["ISSUEERPMATERIALID"].ToString());
                para.Add("ASSEMBLEEMPLOYEEID", context.Request["employeeid"].ToString());
                sqlTran.Add(m_issueData.GetPartsAssembleSql(para));
            }
        }
        result.Result = m_issueData.PartsReceptTran(sqlTran);
        result.Message = result.Result ? "配送成功" : "配送失败";
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void partReceptAccept(HttpContext context) 
    {
        var bigsmall = JsonConvert.DeserializeObject<DataTable>(context.Request["bigsmall"].ToString());
        var sqlTran = new ArrayList();
        int count = 0;
        uMESProcessResult result = new uMESProcessResult();
        foreach(DataRow dr in bigsmall.Rows)
        {
            var Status = m_issueData.GetPartsStatus(dr["ISSUEERPMATERIALID"].ToString());
            if (string.IsNullOrWhiteSpace(Status)) { count++; continue; }
            else { 
               var para=new Dictionary<string,string>();
               para.Add("ISSUEERPMATERIALID", dr["ISSUEERPMATERIALID"].ToString());
               para.Add("ACCEPTEMPLOYEEID", m_UserInfo.EmployeeID); 
               sqlTran.Add(m_issueData.GetPartsAcceptSql(para));
            }
        }
        if (count == 0)
        {
            result.Result = m_issueData.PartsReceptTran(sqlTran);
            result.Message =result.Result? "接收成功":"接收失败";
        }
        else {
            result.Message = "存在未配送的零组件";
        }
       context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getEmployeeByDic(HttpContext context) 
    {
        var para = JsonConvert.DeserializeObject<Dictionary<string,string>>(context.Request["data"].ToString());
        DataTable employeeinfo_dt = m_EmployeeObj.GetEmployeeByDic(para);
        uMESProcessResult result = new uMESProcessResult();
        result.Result = true;
        result.DBTable = employeeinfo_dt;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

    private void getScanContainerData(HttpContext context) 
    {
        var searchText = context.Request["searchText"].ToString();
        var para = new Dictionary<string, string>();
        para.Add("FactoryID", m_UserInfo.FactoryID);//分厂
        para.Add("TeamID", m_UserInfo.TeamID);//班组
        para.Add("WorkerID", m_UserInfo.EmployeeID.ToString());
        if (!string.IsNullOrEmpty(searchText))
        {
            para.Add("ContainerNo", searchText);
        }
        DataTable notReport = m_ReportObj.GetZSWorkReportContainerInfo(para, true);
        if (!string.IsNullOrEmpty(searchText))
        {
            para.Remove("ContainerNo");
            para.Add("mfgordername", searchText);
            notReport.Merge(m_ReportObj.GetZSWorkReportContainerInfo(para, true));
            para.Add("ContainerNo", searchText);
            para.Remove("mfgordername");
        }
        para.Add("notCheck","");
        DataTable notCheck = m_ReportObj.GetZSWorkReportContainerInfo(para, true);
        if (!string.IsNullOrEmpty(searchText))
        {
            para.Remove("ContainerNo");
            para.Add("mfgordername", searchText);
            notCheck.Merge(m_ReportObj.GetZSWorkReportContainerInfo(para, true));
        }
        uMESProcessResult result = new uMESProcessResult();
        result.DBTable = notReport;
        result.ReturnData = notCheck;
        result.Result = true;
        context.Response.Write(JsonConvert.SerializeObject(result));
    }

}